<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Docker 部署 Gitlab Docker 入门教程</title>
    <meta name="description" content="在 Docker 中安装 Gitlab 教程，官方文档，如果你想使用原生安装，教程在这里：CentOS7安装维护Gitlab">
    <meta name="keywords" content="docker,containers,tutorial">
    <link rel="stylesheet" type="text/css" href="../css/main.css?v=1.29.0">
    <link rel="stylesheet" type="text/css" href="../css/tocbot.css?v=1.29.0">
    <link rel="stylesheet" type="text/css" href="../css/media.css?v=1.29.0">
    <link rel="stylesheet" type="text/css" href="../css/sidebar.css?v=1.29.0">
    <link rel="stylesheet" type="text/css" href="../css/copy.css?v=1.29.0">
    <link rel="stylesheet" type="text/css" href="../css/demo-preview.css?v=1.29.0">
    <link rel="icon" href="../img/logo.svg" type="image/x-icon">
    <script src="../js/copy.js?v=1.29.0"></script>
    <script src="../js/dark-mode.js?v=1.29.0"></script>
    <script src="../js/markdown-style.js?v=1.29.0"></script>
  </head>
  <body id="idoctotop"><a href="#idoctotop" class="gototop">top</a>
    <header class="header">
      <article class="inner warpper"><a class="logo" href="../index.html"><svg viewBox="0 0 1280 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
            <path d="M699.88718 472.6h-132.2v-118.8h132.2v118.8z m0-408.6h-132.2v121.4h132.2V64z m156.4 289.6H724.08718v118.8h132.2v-118.8z m-312.6-144.2h-132.2v120.2h132.2v-120.2z m156.2 0h-132.2v120.2h132.2v-120.2z m553.6 200c-28.8-19.4-95.2-26.4-146.2-16.8-6.6-48-33.4-89.8-82.2-127.4l-28-18.6-18.6 28c-36.8 55.6-46.8 147.2-7.4 207.6-17.4 9.4-51.6 22.2-96.8 21.4H4.88718c-17.4 101.6 11.6 233.6 88 324.2 74.2 87.8 185.4 132.4 330.8 132.4 314.8 0 547.8-145 656.8-408.4 42.8 0.8 135.2 0.2 182.6-90.4 3-5 13.2-26.4 17-34.2l-26.6-17.8z m-1022.2-55.8h-132v118.8h132.2v-118.8z m156.2 0h-132.2v118.8h132.2v-118.8z m156.2 0h-132.2v118.8h132.2v-118.8z m-156.2-144.2h-132.2v120.2h132.2v-120.2z" fill="#0187D1"></path>
          </svg>
<span class="title">Docker 入门教程</span></a>
        <div class="content">
          <ul class="menu">
            <li><a href="../index.html" target="" class="">Home</a></li>
            <li><a href="https://wangchujiang.com/#/sponsor" target="__blank" class="">Sponsor</a></li>
          </ul><a href="https://github.com/jaywcjlove/docker-tutorial" target="_blank" rel="noopener noreferrer" title="Github" name="Github" class="github"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
              <path d="M9 19c-5 1.5-5-2.5-7-3m14 6v-3.87a3.37 3.37 0 0 0-.94-2.61c3.14-.35 6.44-1.54 6.44-7A5.44 5.44 0 0 0 20 4.77 5.07 5.07 0 0 0 19.91 1S18.73.65 16 2.48a13.38 13.38 0 0 0-7 0C6.27.65 5.09 1 5.09 1A5.07 5.07 0 0 0 5 4.77a5.44 5.44 0 0 0-1.5 3.78c0 5.42 3.3 6.61 6.44 7A3.37 3.37 0 0 0 9 18.13V22"></path>
            </svg></a>
          <dark-mode permanent=""></dark-mode>
        </div>
      </article>
    </header>
    <div class="warpper-content warpper sidebar">
      <div class="sidebar-border">
        <aside class="sidebar" role="navigation">
          <div>
            <a href="../index.html" class="">入门</a>
            <label>实践</label>
            <a href="../docker-compose.html" class="">Docker Compose</a>
            <a href="../elasticsearch.html" class="">ElasticSearch 搜索服务器</a>
            <a href="index.html" class="active">Gitlab 代码仓库管理系统</a>
            <a href="../harbor.html" class="">Harbor</a>
            <a href="../mattermost.html" class="">Mattermost 聊天工具</a>
            <a href="../mysql.html" class="">MySQL 数据库</a>
            <a href="../nginx.html" class="">Nginx Web 服务器</a>
            <a href="../nps/index.html" class="">NPS 内网穿透</a>
            <a href="../portainer.html" class="">Portainer Docker 管理</a>
            <a href="../postgres.html" class="">PostgreSQL 数据库</a>
            <a href="../penpot.html" class="">Penpot 设计和原型</a>
            <a href="../navidrome.html" class="">Navidrome 音乐服务器</a>
            <a href="../rancher.html" class="">Rancher 容器管理平台</a>
            <a href="../redis.html" class="">Redis 数据库</a>
            <a href="../rocket.chat/index.html" class="">Rocket.Chat 聊天工具</a>
            <a href="../seaweedfs/index.html" class="">SeaweedFS 文件系统</a>
            <a href="../sourcegraph/index.html" class="">Sourcegraph 代码搜索引擎</a>
          </div>
        </aside>
      </div>
      <markdown-style theme-auto-switch-disabled="">
        <h1 id="docker-部署-gitlab"><a aria-hidden="true" tabindex="-1" href="#docker-部署-gitlab" class="anchor"><span class="icon icon-link"></span></a>Docker 部署 Gitlab</h1>
        <p>在 Docker 中安装 Gitlab 教程，<a href="https://docs.gitlab.com/omnibus/docker/">官方文档</a>，如果你想使用原生安装，教程在这里：<a href="https://github.com/jaywcjlove/handbook/blob/9adc40d9e684928ee68d3301afbd78eee7fe3816/CentOS/CentOS7%E5%AE%89%E8%A3%85%E7%BB%B4%E6%8A%A4Gitlab.md">CentOS7安装维护Gitlab</a></p>
        <h2 id="下载镜像"><a aria-hidden="true" tabindex="-1" href="#下载镜像" class="anchor"><span class="icon icon-link"></span></a>下载镜像</h2>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token function">docker</span> pull gitlab/gitlab-ce
</span></code><input type="hidden" value="docker pull gitlab/gitlab-ce
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <h2 id="运行容器"><a aria-hidden="true" tabindex="-1" href="#运行容器" class="anchor"><span class="icon icon-link"></span></a>运行容器</h2>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token function">sudo</span> <span class="token function">docker</span> run <span class="token punctuation">\</span>
</span><span class="code-line line-number" line="2">  <span class="token parameter variable">--hostname</span> gitlab.example.com <span class="token punctuation">\</span>
</span><span class="code-line line-number" line="3">  <span class="token parameter variable">--publish</span> <span class="token number">8443</span>:443 <span class="token parameter variable">--publish</span> <span class="token number">8081</span>:80 <span class="token parameter variable">-p</span> <span class="token number">2222</span>:22 <span class="token punctuation">\</span>
</span><span class="code-line line-number" line="4">  <span class="token parameter variable">--name</span> gitlab <span class="token punctuation">\</span>
</span><span class="code-line line-number" line="5">  <span class="token parameter variable">--restart</span> always <span class="token punctuation">\</span>
</span><span class="code-line line-number" line="6">  <span class="token parameter variable">--volume</span> <span class="token environment constant">$HOME</span>/_docker/gitlab/config:/etc/gitlab <span class="token punctuation">\</span>
</span><span class="code-line line-number" line="7">  <span class="token parameter variable">--volume</span> <span class="token environment constant">$HOME</span>/_docker/gitlab/logs:/var/log/gitlab <span class="token punctuation">\</span>
</span><span class="code-line line-number" line="8">  <span class="token parameter variable">--volume</span> <span class="token environment constant">$HOME</span>/_docker/gitlab/data:/var/opt/gitlab <span class="token punctuation">\</span>
</span><span class="code-line line-number" line="9">  <span class="token parameter variable">-v</span> /etc/localtime:/etc/localtime <span class="token punctuation">\</span>
</span><span class="code-line line-number" line="10">  <span class="token parameter variable">-d</span> <span class="token punctuation">\</span>
</span><span class="code-line line-number" line="11">  gitlab/gitlab-ce:latest
</span></code><input type="hidden" value="sudo docker run \
  --hostname gitlab.example.com \
  --publish 8443:443 --publish 8081:80 -p 2222:22 \
  --name gitlab \
  --restart always \
  --volume $HOME/_docker/gitlab/config:/etc/gitlab \
  --volume $HOME/_docker/gitlab/logs:/var/log/gitlab \
  --volume $HOME/_docker/gitlab/data:/var/opt/gitlab \
  -v /etc/localtime:/etc/localtime \
  -d \
  gitlab/gitlab-ce:latest
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>由于端口冲突，重新映射了一个端口 <code>2222</code>，如果不想麻烦，可以事先将 ssh 端口号更改成别的端口号，<a href="https://github.com/jaywcjlove/handbook/blob/9adc40d9e684928ee68d3301afbd78eee7fe3816/CentOS/%E4%BF%AE%E6%94%B9ssh%E7%AB%AF%E5%8F%A3%E5%8F%B7%E7%9A%84%E6%96%B9%E6%B3%95.md">修改ssh端口号的方法</a></p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token comment"># 要从之前的：</span>
</span><span class="code-line line-number" line="2"><span class="token function">git</span> clone git@gitlab.example.com:myuser/awesome-project.git
</span><span class="code-line line-number" line="3"><span class="token comment"># 改为明确使用 `ssh://` 的 `URL` 方式。</span>
</span><span class="code-line line-number" line="4"><span class="token function">git</span> clone ssh://git@gitlab.example.com:2222/myuser/awesome-project.git
</span></code><input type="hidden" value="# 要从之前的：
git clone git@gitlab.example.com:myuser/awesome-project.git
# 改为明确使用 &#x60;ssh://&#x60; 的 &#x60;URL&#x60; 方式。
git clone ssh://git@gitlab.example.com:2222/myuser/awesome-project.git
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>为了克隆不必麻烦，保留 <code>gitlab</code> 的 <code>22</code> 端口映射，将主机的 <code>sshd</code> 的 <code>22</code> 端口映射到容器中去。将主机的 sshd 端口更改为 <code>2222</code></p>
        <p>编辑文件 <code>/etc/ssh/sshd_config</code>，将其中的 <code>#Port 22</code> 注释去掉，将数字 <code>22</code> 更改为 <code>2222</code>，执行下面的命令重启 <code>sshd</code> 服务</p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1">systemctl restart sshd
</span></code><input type="hidden" value="systemctl restart sshd
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>防火墙的规则，添加开发 <code>2222</code> 端口</p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1">iptables <span class="token parameter variable">-A</span> INPUT <span class="token parameter variable">-p</span> tcp <span class="token parameter variable">--dport</span> <span class="token number">2222</span> <span class="token parameter variable">-j</span> ACCEPT
</span><span class="code-line line-number" line="2">iptables <span class="token parameter variable">-A</span> OUTPUT <span class="token parameter variable">-p</span> tcp <span class="token parameter variable">--sport</span> <span class="token number">2222</span> <span class="token parameter variable">-j</span> ACCEPT
</span><span class="code-line line-number" line="3"><span class="token comment"># 再查看下是否添加上去, 看到添加了</span>
</span><span class="code-line line-number" line="4">iptables <span class="token parameter variable">-L</span> <span class="token parameter variable">-n</span>
</span></code><input type="hidden" value="iptables -A INPUT -p tcp --dport 2222 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 2222 -j ACCEPT
# 再查看下是否添加上去, 看到添加了
iptables -L -n
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>如果此容器由于权限问题而无法启动，请尝试通过执行以下操作来修复它：</p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token function">docker</span> <span class="token builtin class-name">exec</span> <span class="token parameter variable">-it</span> gitlab update-permissions
</span><span class="code-line line-number" line="2"><span class="token function">docker</span> restart gitlab
</span></code><input type="hidden" value="docker exec -it gitlab update-permissions
docker restart gitlab
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <h2 id="容器手动备份"><a aria-hidden="true" tabindex="-1" href="#容器手动备份" class="anchor"><span class="icon icon-link"></span></a>容器手动备份</h2>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token comment"># 第一种进行入容器执行命令的方法进行手工备份</span>
</span><span class="code-line line-number" line="2"><span class="token function">docker</span> <span class="token builtin class-name">exec</span> <span class="token parameter variable">-it</span> 容器名或容器id <span class="token function">bash</span>  <span class="token comment"># 进入容器</span>
</span><span class="code-line line-number" line="3">gitlab-rake gitlab:backup:create   <span class="token comment"># 执行gitlab备份命令</span>
</span><span class="code-line line-number" line="4">
</span><span class="code-line line-number" line="5"><span class="token comment"># 第二种直接使用外部命令执行，一次完成</span>
</span><span class="code-line line-number" line="6"><span class="token function">docker</span> <span class="token builtin class-name">exec</span> 容器名或容器id gitlab-rake gitlab:backup:create
</span></code><input type="hidden" value="# 第一种进行入容器执行命令的方法进行手工备份
docker exec -it 容器名或容器id bash  # 进入容器
gitlab-rake gitlab:backup:create   # 执行gitlab备份命令

# 第二种直接使用外部命令执行，一次完成
docker exec 容器名或容器id gitlab-rake gitlab:backup:create
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>若结果显示 <code>Errno::EACCES: Permission denied @ dir_s_mkdir - /var/opt/gitlab/backups/db</code>，则说明当前路径的 <code>权限不足</code> 以及 <code>拥有者</code> 错误，需要授予当前路径对应的权限并把拥有者改为 <code>git</code>。进入容器执行下面命令：</p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token function">chmod</span> <span class="token parameter variable">-R</span> <span class="token number">755</span> /var/opt/gitlab/backups
</span><span class="code-line line-number" line="2"><span class="token function">chown</span> <span class="token parameter variable">-R</span> git:git /var/opt/gitlab/backups
</span></code><input type="hidden" value="chmod -R 755 /var/opt/gitlab/backups
chown -R git:git /var/opt/gitlab/backups
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <h3 id="自动备份"><a aria-hidden="true" tabindex="-1" href="#自动备份" class="anchor"><span class="icon icon-link"></span></a>自动备份</h3>
        <p>通过在宿主机上使用 crontab 使用备份命令实现自动备份</p>
        <p>添加备份脚本 <code>vi ~/_docker/gitlab/gitlab.backup.sh</code>，将下面内容添加到脚本中，保存之后添加可执行权限 <code>chmod +x gitlab.backup.sh</code></p>
        <pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1"><span class="token shebang important">#!/bin/bash</span>
</span><span class="code-line line-number" line="2"><span class="token keyword">case</span> <span class="token string">"<span class="token variable">$1</span>"</span> <span class="token keyword">in</span> 
</span><span class="code-line line-number" line="3">  start<span class="token punctuation">)</span>
</span><span class="code-line line-number" line="4">    <span class="token function">docker</span> <span class="token builtin class-name">exec</span> gitlab-ce11.2.3 gitlab-rake gitlab:backup:create
</span><span class="code-line line-number" line="5">    <span class="token punctuation">;</span><span class="token punctuation">;</span>
</span><span class="code-line line-number" line="6"><span class="token keyword">esac</span>
</span></code><input type="hidden" value="#!/bin/bash
case &#x22;$1&#x22; in 
  start)
    docker exec gitlab-ce11.2.3 gitlab-rake gitlab:backup:create
    ;;
esac
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>创建定时执行计划</p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token function">crontab</span> <span class="token parameter variable">-e</span> <span class="token comment"># 进入编辑，添加下面内容</span>
</span><span class="code-line line-number" line="2">
</span><span class="code-line line-number" line="3"><span class="token comment"># 每天2点备份 gitlab 数据</span>
</span><span class="code-line line-number" line="4"><span class="token number">0</span> <span class="token number">2</span> * * * <span class="token environment constant">$HOME</span>/_docker/gitlab/gitlab.backup.sh start
</span><span class="code-line line-number" line="5"><span class="token comment"># *  *  *  *  *  command</span>
</span><span class="code-line line-number" line="6"><span class="token comment"># 分  时  日  月  周  命令</span>
</span><span class="code-line line-number" line="7">
</span><span class="code-line line-number" line="8"><span class="token comment"># 其中，</span>
</span><span class="code-line line-number" line="9"><span class="token comment"># 第1列表示分钟，1~59，每分钟用*表示</span>
</span><span class="code-line line-number" line="10"><span class="token comment"># 第2列表示小时，1~23，（0表示0点）</span>
</span><span class="code-line line-number" line="11"><span class="token comment"># 第3列表示日期，1~31</span>
</span><span class="code-line line-number" line="12"><span class="token comment"># 第4列表示月份，1~12</span>
</span><span class="code-line line-number" line="13"><span class="token comment"># 第5列表示星期，0~6（0表示星期天）</span>
</span><span class="code-line line-number" line="14"><span class="token comment"># 第六列表示要运行的命令。</span>
</span></code><input type="hidden" value="crontab -e # 进入编辑，添加下面内容

# 每天2点备份 gitlab 数据
0 2 * * * $HOME/_docker/gitlab/gitlab.backup.sh start
# *  *  *  *  *  command
# 分  时  日  月  周  命令

# 其中，
# 第1列表示分钟，1~59，每分钟用*表示
# 第2列表示小时，1~23，（0表示0点）
# 第3列表示日期，1~31
# 第4列表示月份，1~12
# 第5列表示星期，0~6（0表示星期天）
# 第六列表示要运行的命令。
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>上面两行保存之后，重新载入配置</p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token function">service</span> crond reload
</span><span class="code-line line-number" line="2"><span class="token comment"># or</span>
</span><span class="code-line line-number" line="3">systemctl reload crond.service
</span></code><input type="hidden" value="service crond reload
# or
systemctl reload crond.service
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <h3 id="备份保留七天"><a aria-hidden="true" tabindex="-1" href="#备份保留七天" class="anchor"><span class="icon icon-link"></span></a>备份保留七天</h3>
        <p>设置只保存最近7天的备份，编辑 <code>vi $HOME/_docker/gitlab/config/gitlab.rb</code> 配置文件，找到如下代码，删除注释 <code>#</code> 保存</p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token comment"># /etc/gitlab/gitlab.rb 配置文件 修改下面这一行</span>
</span><span class="code-line line-number" line="2">gitlab_rails<span class="token punctuation">[</span><span class="token string">'backup_keep_time'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">604800</span>  
</span></code><input type="hidden" value="# /etc/gitlab/gitlab.rb 配置文件 修改下面这一行
gitlab_rails[&#x27;backup_keep_time&#x27;] = 604800  
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>重新加载 <code>gitlab</code> 配置文件</p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token function">docker</span> <span class="token builtin class-name">exec</span> 容器名或容器ID gitlab-ctl reconfigure  
</span></code><input type="hidden" value="docker exec 容器名或容器ID gitlab-ctl reconfigure  
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <h2 id="容器管理"><a aria-hidden="true" tabindex="-1" href="#容器管理" class="anchor"><span class="icon icon-link"></span></a>容器管理</h2>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token function">docker</span> stop gitlab <span class="token comment"># 停止容器</span>
</span><span class="code-line line-number" line="2"><span class="token function">docker</span> <span class="token function">rm</span> gitlab <span class="token comment"># 删除容器</span>
</span><span class="code-line line-number" line="3"><span class="token function">docker</span> start gitlab <span class="token comment"># 启动容器</span>
</span><span class="code-line line-number" line="4"><span class="token comment"># 编辑 gitlab 容器配置</span>
</span><span class="code-line line-number" line="5"><span class="token function">docker</span> <span class="token builtin class-name">exec</span> <span class="token parameter variable">-it</span> gitlab <span class="token function">vim</span> /etc/gitlab/gitlab.rb
</span><span class="code-line line-number" line="6"><span class="token comment"># 重启 gitlab 容器</span>
</span><span class="code-line line-number" line="7"><span class="token function">docker</span> restart gitlab
</span></code><input type="hidden" value="docker stop gitlab # 停止容器
docker rm gitlab # 删除容器
docker start gitlab # 启动容器
# 编辑 gitlab 容器配置
docker exec -it gitlab vim /etc/gitlab/gitlab.rb
# 重启 gitlab 容器
docker restart gitlab
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <h2 id="通过-docker-compose-安装"><a aria-hidden="true" tabindex="-1" href="#通过-docker-compose-安装" class="anchor"><span class="icon icon-link"></span></a>通过 Docker Compose 安装</h2>
        <p>使用 Docker Compose，可以轻松配置，安装和升级基于 Docker 的 GitLab 安装，<a href="https://docs.gitlab.com/omnibus/docker/README.html#install-gitlab-using-docker-compose">官方教程在这里</a>。</p>
        <p><strong>第一步：</strong> Docker <a href="https://docs.docker.com/compose/install/">官方教程安装</a> Docker Compose。</p>
        <p><strong>第二步：</strong> 创建 <code>docker-compose.yml</code> 文件，将下面配置复制到文件中 (或者下载<a href="https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/docker/docker-compose.yml">官方示例</a>):</p>
        <pre class="language-yaml"><code class="language-yaml code-highlight"><span class="code-line line-number" line="1"><span class="token key atrule">web</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="2">  <span class="token key atrule">image</span><span class="token punctuation">:</span> <span class="token string">'gitlab/gitlab-ce:latest'</span>
</span><span class="code-line line-number" line="3">  <span class="token key atrule">restart</span><span class="token punctuation">:</span> always
</span><span class="code-line line-number" line="4">  <span class="token key atrule">hostname</span><span class="token punctuation">:</span> <span class="token string">'gitlab.example.com'</span>
</span><span class="code-line line-number" line="5">  <span class="token key atrule">environment</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="6">    <span class="token key atrule">GITLAB_OMNIBUS_CONFIG</span><span class="token punctuation">:</span> <span class="token punctuation">|</span><span class="token scalar string">
</span></span><span class="code-line line-number" line="7"><span class="token scalar string">      external_url 'https://gitlab.example.com'
</span></span><span class="code-line line-number" line="8"><span class="token scalar string">      gitlab_rails['time_zone'] = 'Asia/Shanghai'
</span></span><span class="code-line line-number" line="9"><span class="token scalar string">      gitlab_rails['backup_keep_time'] = 259200 # 3 Day, 259200 seconds 
</span></span><span class="code-line line-number" line="10"><span class="token scalar string">      registry_external_url 'http://192.168.188.222:5008'</span>
</span><span class="code-line line-number" line="11">  <span class="token key atrule">ports</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="12">    <span class="token punctuation">-</span> <span class="token string">'8081:80'</span>
</span><span class="code-line line-number" line="13">    <span class="token punctuation">-</span> <span class="token string">'8443:443'</span>
</span><span class="code-line line-number" line="14">    <span class="token punctuation">-</span> <span class="token string">'22:22'</span>
</span><span class="code-line line-number" line="15">  <span class="token key atrule">volumes</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="16">    <span class="token punctuation">-</span> ./gitlab<span class="token punctuation">-</span>data/config<span class="token punctuation">:</span>/etc/gitlab
</span><span class="code-line line-number" line="17">    <span class="token punctuation">-</span> ./gitlab<span class="token punctuation">-</span>data/logs<span class="token punctuation">:</span>/var/log/gitlab
</span><span class="code-line line-number" line="18">    <span class="token punctuation">-</span> ./gitlab<span class="token punctuation">-</span>data/data<span class="token punctuation">:</span>/var/opt/gitlab
</span><span class="code-line line-number" line="19">    <span class="token punctuation">-</span> /etc/localtime<span class="token punctuation">:</span>/etc/localtime
</span></code><input type="hidden" value="web:
  image: &#x27;gitlab/gitlab-ce:latest&#x27;
  restart: always
  hostname: &#x27;gitlab.example.com&#x27;
  environment:
    GITLAB_OMNIBUS_CONFIG: |
      external_url &#x27;https://gitlab.example.com&#x27;
      gitlab_rails[&#x27;time_zone&#x27;] = &#x27;Asia/Shanghai&#x27;
      gitlab_rails[&#x27;backup_keep_time&#x27;] = 259200 # 3 Day, 259200 seconds 
      registry_external_url &#x27;http://192.168.188.222:5008&#x27;
  ports:
    - &#x27;8081:80&#x27;
    - &#x27;8443:443&#x27;
    - &#x27;22:22&#x27;
  volumes:
    - ./gitlab-data/config:/etc/gitlab
    - ./gitlab-data/logs:/var/log/gitlab
    - ./gitlab-data/data:/var/opt/gitlab
    - /etc/localtime:/etc/localtime
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p><strong>第三步：</strong> 确保与 <code>docker-compose.yml</code> 文件同一目录下运行 <code>docker-compose up -d</code> 启动 Gitlab</p>
        <h2 id="使用-docker-swarm"><a aria-hidden="true" tabindex="-1" href="#使用-docker-swarm" class="anchor"><span class="icon icon-link"></span></a>使用 Docker Swarm</h2>
        <p><a href="https://docs.gitlab.com/omnibus/docker/README.html#deploy-gitlab-in-a-docker-swarm">官方教程</a> 创建 <code>docker-compose.yml</code> 文件</p>
        <pre class="language-yaml"><code class="language-yaml code-highlight"><span class="code-line line-number" line="1"><span class="token key atrule">version</span><span class="token punctuation">:</span> <span class="token string">"3.6"</span>
</span><span class="code-line line-number" line="2"><span class="token key atrule">services</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="3">  <span class="token key atrule">gitlab</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="4">    <span class="token key atrule">image</span><span class="token punctuation">:</span> gitlab/gitlab<span class="token punctuation">-</span>ce<span class="token punctuation">:</span>latest
</span><span class="code-line line-number" line="5">    <span class="token key atrule">container_name</span><span class="token punctuation">:</span> gitlab
</span><span class="code-line line-number" line="6">    <span class="token key atrule">ports</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="7">      <span class="token punctuation">-</span> <span class="token string">"22:22"</span>
</span><span class="code-line line-number" line="8">      <span class="token punctuation">-</span> <span class="token string">"80:80"</span>
</span><span class="code-line line-number" line="9">      <span class="token punctuation">-</span> <span class="token string">"443:443"</span>
</span><span class="code-line line-number" line="10">    <span class="token key atrule">volumes</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="11">      <span class="token punctuation">-</span> /srv/gitlab/data<span class="token punctuation">:</span>/var/opt/gitlab
</span><span class="code-line line-number" line="12">      <span class="token punctuation">-</span> /srv/gitlab/logs<span class="token punctuation">:</span>/var/log/gitlab
</span><span class="code-line line-number" line="13">      <span class="token punctuation">-</span> /srv/gitlab/config<span class="token punctuation">:</span>/etc/gitlab
</span><span class="code-line line-number" line="14">      <span class="token punctuation">-</span> /etc/localtime<span class="token punctuation">:</span>/etc/localtime
</span><span class="code-line line-number" line="15">    <span class="token key atrule">environment</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="16">      <span class="token key atrule">GITLAB_OMNIBUS_CONFIG</span><span class="token punctuation">:</span> <span class="token string">"from_file('/omnibus_config.rb')"</span>
</span><span class="code-line line-number" line="17">    <span class="token key atrule">configs</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="18">      <span class="token punctuation">-</span> <span class="token key atrule">source</span><span class="token punctuation">:</span> gitlab
</span><span class="code-line line-number" line="19">        <span class="token key atrule">target</span><span class="token punctuation">:</span> /omnibus_config.rb
</span><span class="code-line line-number" line="20">    <span class="token key atrule">secrets</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="21">      <span class="token punctuation">-</span> gitlab_root_password
</span><span class="code-line line-number" line="22">  <span class="token key atrule">gitlab-runner</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="23">    <span class="token key atrule">image</span><span class="token punctuation">:</span> gitlab/gitlab<span class="token punctuation">-</span>runner<span class="token punctuation">:</span>alpine
</span><span class="code-line line-number" line="24">    <span class="token key atrule">container_name</span><span class="token punctuation">:</span> gitlab<span class="token punctuation">-</span>runner
</span><span class="code-line line-number" line="25">    <span class="token key atrule">deploy</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="26">      <span class="token key atrule">mode</span><span class="token punctuation">:</span> replicated
</span><span class="code-line line-number" line="27">      <span class="token key atrule">replicas</span><span class="token punctuation">:</span> <span class="token number">4</span>
</span><span class="code-line line-number" line="28"><span class="token key atrule">configs</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="29">  <span class="token key atrule">gitlab</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="30">    <span class="token key atrule">file</span><span class="token punctuation">:</span> ./gitlab.rb
</span><span class="code-line line-number" line="31"><span class="token key atrule">secrets</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="32">  <span class="token key atrule">gitlab_root_password</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="33">    <span class="token key atrule">file</span><span class="token punctuation">:</span> ./root_password.txt
</span></code><input type="hidden" value="version: &#x22;3.6&#x22;
services:
  gitlab:
    image: gitlab/gitlab-ce:latest
    container_name: gitlab
    ports:
      - &#x22;22:22&#x22;
      - &#x22;80:80&#x22;
      - &#x22;443:443&#x22;
    volumes:
      - /srv/gitlab/data:/var/opt/gitlab
      - /srv/gitlab/logs:/var/log/gitlab
      - /srv/gitlab/config:/etc/gitlab
      - /etc/localtime:/etc/localtime
    environment:
      GITLAB_OMNIBUS_CONFIG: &#x22;from_file(&#x27;/omnibus_config.rb&#x27;)&#x22;
    configs:
      - source: gitlab
        target: /omnibus_config.rb
    secrets:
      - gitlab_root_password
  gitlab-runner:
    image: gitlab/gitlab-runner:alpine
    container_name: gitlab-runner
    deploy:
      mode: replicated
      replicas: 4
configs:
  gitlab:
    file: ./gitlab.rb
secrets:
  gitlab_root_password:
    file: ./root_password.txt
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>创建 <code>gitlab.rb</code> 文件</p>
        <pre class="language-rb"><code class="language-rb code-highlight"><span class="code-line line-number" line="1">external_url <span class="token string-literal"><span class="token string">'https://my.domain.com/'</span></span>
</span><span class="code-line line-number" line="2">gitlab_rails<span class="token punctuation">[</span><span class="token string-literal"><span class="token string">'initial_root_password'</span></span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token builtin">File</span><span class="token punctuation">.</span>read<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">'/run/secrets/gitlab_root_password'</span></span><span class="token punctuation">)</span>
</span><span class="code-line line-number" line="3">gitlab_rails<span class="token punctuation">[</span><span class="token string-literal"><span class="token string">'backup_keep_time'</span></span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">604800</span> 
</span><span class="code-line line-number" line="4">gitlab_rails<span class="token punctuation">[</span><span class="token string-literal"><span class="token string">'time_zone'</span></span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string-literal"><span class="token string">'Asia/Shanghai'</span></span> <span class="token comment"># 中国的东八区时间</span>
</span></code><input type="hidden" value="external_url &#x27;https://my.domain.com/&#x27;
gitlab_rails[&#x27;initial_root_password&#x27;] = File.read(&#x27;/run/secrets/gitlab_root_password&#x27;)
gitlab_rails[&#x27;backup_keep_time&#x27;] = 604800 
gitlab_rails[&#x27;time_zone&#x27;] = &#x27;Asia/Shanghai&#x27; # 中国的东八区时间
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>由于新版 <code>docker-runner</code> 不支持 <code>https</code>，必须设置 <code>ssl</code></p>
        <pre class="language-rb"><code class="language-rb code-highlight"><span class="code-line line-number" line="1">nginx<span class="token punctuation">[</span><span class="token string-literal"><span class="token string">'redirect_http_to_https'</span></span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token boolean">false</span>
</span><span class="code-line line-number" line="2">nginx<span class="token punctuation">[</span><span class="token string-literal"><span class="token string">'ssl_certificate'</span></span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string-literal"><span class="token string">"/var/opt/gitlab/ssl/fullchain.pem"</span></span>
</span><span class="code-line line-number" line="3">nginx<span class="token punctuation">[</span><span class="token string-literal"><span class="token string">'ssl_certificate_key'</span></span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string-literal"><span class="token string">"/var/opt/gitlab/ssl/privkey.pem"</span></span>
</span></code><input type="hidden" value="nginx[&#x27;redirect_http_to_https&#x27;] = false
nginx[&#x27;ssl_certificate&#x27;] = &#x22;/var/opt/gitlab/ssl/fullchain.pem&#x22;
nginx[&#x27;ssl_certificate_key&#x27;] = &#x22;/var/opt/gitlab/ssl/privkey.pem&#x22;
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>创建 <code>root_password.txt</code> 文件</p>
        <pre><code class="code-highlight"><span class="code-line line-number" line="1">MySuperSecretAndSecurePass0rd!
</span></code><input type="hidden" value="MySuperSecretAndSecurePass0rd!
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>确保您与 <code>docker-compose.yml</code> 在同一目录中并运行：</p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token function">docker</span> stack deploy --compose-file docker-compose.yml gitlab
</span></code><input type="hidden" value="docker stack deploy --compose-file docker-compose.yml gitlab
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <h2 id="注册-runner"><a aria-hidden="true" tabindex="-1" href="#注册-runner" class="anchor"><span class="icon icon-link"></span></a>注册 Runner</h2>
        <p>官方 <a href="https://docs.gitlab.com/runner/install/docker.html"><code>注册 runner</code></a> 文档</p>
        <h3 id="更新配置"><a aria-hidden="true" tabindex="-1" href="#更新配置" class="anchor"><span class="icon icon-link"></span></a>更新配置</h3>
        <p>如果您在 <code>config.toml</code> 中更改配置，则可能需要重新启动运行程序以应用更改。 确保重新启动整个容器，而不是使用 <code>gitlab-runner restart</code>：</p>
        <pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1"><span class="token function">docker</span> restart gitlab-runner
</span></code><input type="hidden" value="docker restart gitlab-runner
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <h3 id="升级版本"><a aria-hidden="true" tabindex="-1" href="#升级版本" class="anchor"><span class="icon icon-link"></span></a>升级版本</h3>
        <p>Pull the latest version (or a specific tag):</p>
        <pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1"><span class="token function">docker</span> pull gitlab/gitlab-runner:latest
</span></code><input type="hidden" value="docker pull gitlab/gitlab-runner:latest
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>Stop and remove the existing container:</p>
        <pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1"><span class="token function">docker</span> stop gitlab-runner <span class="token operator">&#x26;&#x26;</span> <span class="token function">docker</span> <span class="token function">rm</span> gitlab-runner
</span></code><input type="hidden" value="docker stop gitlab-runner &#x26;&#x26; docker rm gitlab-runner
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>Start the container as you did originally:</p>
        <pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1"><span class="token function">docker</span> run <span class="token parameter variable">-d</span> <span class="token parameter variable">--name</span> gitlab-runner <span class="token parameter variable">--restart</span> always <span class="token punctuation">\</span>
</span><span class="code-line line-number" line="2">  <span class="token parameter variable">-v</span> /var/run/docker.sock:/var/run/docker.sock <span class="token punctuation">\</span>
</span><span class="code-line line-number" line="3">  <span class="token parameter variable">-v</span> /home/www/gitlab/gitlab-runner/config:/etc/gitlab-runner <span class="token punctuation">\</span>
</span><span class="code-line line-number" line="4">  gitlab/gitlab-runner:latest
</span></code><input type="hidden" value="docker run -d --name gitlab-runner --restart always \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v /home/www/gitlab/gitlab-runner/config:/etc/gitlab-runner \
  gitlab/gitlab-runner:latest
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>服务 gitlab-runner 跑起来之后可以注册对应的仓库</p>
        <pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1"><span class="token function">docker</span> run <span class="token parameter variable">--rm</span> <span class="token parameter variable">-it</span> <span class="token parameter variable">-v</span> /home/www/gitlab/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register
</span><span class="code-line line-number" line="2">
</span><span class="code-line line-number" line="3"><span class="token comment"># Runtime platform                                    arch=amd64 os=linux pid=8 revision=943fc252 version=13.7.0</span>
</span><span class="code-line line-number" line="4"><span class="token comment"># Running in system-mode.</span>
</span><span class="code-line line-number" line="5">
</span><span class="code-line line-number" line="6"><span class="token comment"># Enter the GitLab instance URL (for example, https://gitlab.com/):</span>
</span><span class="code-line line-number" line="7"><span class="token comment"># https://g.xxxxx.cn/</span>
</span><span class="code-line line-number" line="8"><span class="token comment"># Enter the registration token:</span>
</span><span class="code-line line-number" line="9"><span class="token comment"># ze9H4**********</span>
</span><span class="code-line line-number" line="10"><span class="token comment"># Enter a description for the runner:</span>
</span><span class="code-line line-number" line="11"><span class="token comment"># [7d0472a5e808]: web</span>
</span><span class="code-line line-number" line="12"><span class="token comment"># Enter tags for the runner (comma-separated):</span>
</span><span class="code-line line-number" line="13">
</span><span class="code-line line-number" line="14"><span class="token comment"># Registering runner... succeeded                     runner=ze9H44QH</span>
</span><span class="code-line line-number" line="15"><span class="token comment"># Enter an executor: docker-ssh+machine, docker-ssh, parallels, virtualbox, docker+machine, kubernetes, custom, docker, shell, ssh:</span>
</span><span class="code-line line-number" line="16"><span class="token comment"># shell</span>
</span><span class="code-line line-number" line="17"><span class="token comment"># Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!</span>
</span></code><input type="hidden" value="docker run --rm -it -v /home/www/gitlab/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register

# Runtime platform                                    arch=amd64 os=linux pid=8 revision=943fc252 version=13.7.0
# Running in system-mode.

# Enter the GitLab instance URL (for example, https://gitlab.com/):
# https://g.xxxxx.cn/
# Enter the registration token:
# ze9H4**********
# Enter a description for the runner:
# [7d0472a5e808]: web
# Enter tags for the runner (comma-separated):

# Registering runner... succeeded                     runner=ze9H44QH
# Enter an executor: docker-ssh+machine, docker-ssh, parallels, virtualbox, docker+machine, kubernetes, custom, docker, shell, ssh:
# shell
# Runner registered successfully. Feel free to start it, but if it&#x27;s running already the config should be automatically reloaded!
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <ul>
          <li><a href="https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Nodejs.gitlab-ci.yml">gitlab-ci templates</a></li>
        </ul>
        <pre class="language-toml"><code class="language-toml code-highlight"><span class="code-line line-number" line="1"><span class="token key property">concurrent</span> <span class="token punctuation">=</span> <span class="token number">1</span>
</span><span class="code-line line-number" line="2"><span class="token key property">check_interval</span> <span class="token punctuation">=</span> <span class="token number">0</span>
</span><span class="code-line line-number" line="3">
</span><span class="code-line line-number" line="4"><span class="token punctuation">[</span><span class="token table class-name">session_server</span><span class="token punctuation">]</span>
</span><span class="code-line line-number" line="5">  <span class="token key property">session_timeout</span> <span class="token punctuation">=</span> <span class="token number">1800</span>
</span><span class="code-line line-number" line="6">
</span><span class="code-line line-number" line="7"><span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token table class-name">runners</span><span class="token punctuation">]</span><span class="token punctuation">]</span>
</span><span class="code-line line-number" line="8">  <span class="token key property">name</span> <span class="token punctuation">=</span> <span class="token string">"项目名称"</span>
</span><span class="code-line line-number" line="9">  <span class="token key property">url</span> <span class="token punctuation">=</span> <span class="token string">"https://g.xxxxx.cn/"</span>
</span><span class="code-line line-number" line="10">  <span class="token key property">token</span> <span class="token punctuation">=</span> <span class="token string">"xxx-y1vb"</span>
</span><span class="code-line line-number" line="11">  <span class="token key property">executor</span> <span class="token punctuation">=</span> <span class="token string">"docker"</span>
</span><span class="code-line line-number" line="12">
</span><span class="code-line line-number" line="13">  <span class="token punctuation">[</span><span class="token table class-name">runners.custom_build_dir</span><span class="token punctuation">]</span>
</span><span class="code-line line-number" line="14">  <span class="token punctuation">[</span><span class="token table class-name">runners.cache</span><span class="token punctuation">]</span>
</span><span class="code-line line-number" line="15">    <span class="token punctuation">[</span><span class="token table class-name">runners.cache.s3</span><span class="token punctuation">]</span>
</span><span class="code-line line-number" line="16">    <span class="token punctuation">[</span><span class="token table class-name">runners.cache.gcs</span><span class="token punctuation">]</span>
</span><span class="code-line line-number" line="17">    <span class="token punctuation">[</span><span class="token table class-name">runners.cache.azure</span><span class="token punctuation">]</span>
</span><span class="code-line line-number" line="18">  <span class="token punctuation">[</span><span class="token table class-name">runners.docker</span><span class="token punctuation">]</span>
</span><span class="code-line line-number" line="19">    <span class="token key property">environment</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">'GIT_SSL_NO_VERIFY=true'</span><span class="token punctuation">]</span>
</span><span class="code-line line-number" line="20">    <span class="token key property">tls_verify</span> <span class="token punctuation">=</span> <span class="token boolean">false</span>
</span><span class="code-line line-number" line="21">    <span class="token key property">image</span> <span class="token punctuation">=</span> <span class="token string">"node:12"</span>
</span><span class="code-line line-number" line="22">    <span class="token key property">privileged</span> <span class="token punctuation">=</span> <span class="token boolean">false</span>
</span><span class="code-line line-number" line="23">    <span class="token key property">pull_policy</span> <span class="token punctuation">=</span> <span class="token string">"if-not-present"</span>
</span><span class="code-line line-number" line="24">    <span class="token key property">disable_entrypoint_overwrite</span> <span class="token punctuation">=</span> <span class="token boolean">false</span>
</span><span class="code-line line-number" line="25">    <span class="token key property">oom_kill_disable</span> <span class="token punctuation">=</span> <span class="token boolean">false</span>
</span><span class="code-line line-number" line="26">    <span class="token key property">disable_cache</span> <span class="token punctuation">=</span> <span class="token boolean">false</span>
</span><span class="code-line line-number" line="27">    <span class="token key property">volumes</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"/cache"</span><span class="token punctuation">,</span> <span class="token string">"/var/run/docker.sock:/var/run/docker.sock"</span><span class="token punctuation">]</span>
</span><span class="code-line line-number" line="28">    <span class="token key property">shm_size</span> <span class="token punctuation">=</span> <span class="token number">0</span>
</span></code><input type="hidden" value="concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = &#x22;项目名称&#x22;
  url = &#x22;https://g.xxxxx.cn/&#x22;
  token = &#x22;xxx-y1vb&#x22;
  executor = &#x22;docker&#x22;

  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
  [runners.docker]
    environment = [&#x27;GIT_SSL_NO_VERIFY=true&#x27;]
    tls_verify = false
    image = &#x22;node:12&#x22;
    privileged = false
    pull_policy = &#x22;if-not-present&#x22;
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = [&#x22;/cache&#x22;, &#x22;/var/run/docker.sock:/var/run/docker.sock&#x22;]
    shm_size = 0
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <ol>
          <li>⚠️ <code>token</code> 是生成的，必须通过 <code>gitlab-runner</code> 生成 <code>token</code></li>
          <li><code>volumes = ["/cache", "/var/run/docker.sock:/var/run/docker.sock"]</code> 配置添加很重要，解决下面错误：</li>
        </ol>
        <pre><code class="code-highlight"><span class="code-line line-number" line="1">ERROR: error during connect: Get http://docker:2375/v1.40/info: dial tcp: lookup docker on 8.8.8.8:53: no such host
</span></code><input type="hidden" value="ERROR: error during connect: Get http://docker:2375/v1.40/info: dial tcp: lookup docker on 8.8.8.8:53: no such host
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <ol start="3">
          <li><code>pull_policy = "if-not-present"</code> 策略改为：镜像不存在时才拉取。</li>
          <li>Gitlab runner: This job is stuck because the project doesn't have any runners online assigned to it.</li>
        </ol>
        <p>工作被卡住了，因为你的 runner 有标签，但你的 job 没有。 按照以下 4 个步骤，让您的 runner 在没有标签的情况下运行：</p>
        <p>
          <img src="001.png" alt="Gitlab runner">
        </p>
        <p>
          <img src="002.png" alt="Gitlab runner">
        </p>
        <h2 id="ci-中使用编译提交镜像"><a aria-hidden="true" tabindex="-1" href="#ci-中使用编译提交镜像" class="anchor"><span class="icon icon-link"></span></a>CI 中使用编译提交镜像</h2>
        <p>下面是 <a href="https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Docker.gitlab-ci.yml">官方仓库 Docker.gitlab-ci.yml</a> 模板</p>
        <pre class="language-yml"><code class="language-yml code-highlight"><span class="code-line line-number" line="1"><span class="token key atrule">docker-build-master</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="2">  <span class="token comment"># Official docker image.</span>
</span><span class="code-line line-number" line="3">  <span class="token key atrule">image</span><span class="token punctuation">:</span> docker<span class="token punctuation">:</span>latest
</span><span class="code-line line-number" line="4">  <span class="token key atrule">stage</span><span class="token punctuation">:</span> build
</span><span class="code-line line-number" line="5">  <span class="token key atrule">services</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="6">    <span class="token punctuation">-</span> docker<span class="token punctuation">:</span>dind
</span><span class="code-line line-number" line="7">  <span class="token key atrule">before_script</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="8">    <span class="token punctuation">-</span> docker login <span class="token punctuation">-</span>u "$CI_REGISTRY_USER" <span class="token punctuation">-</span>p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
</span><span class="code-line line-number" line="9">  <span class="token key atrule">script</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="10">    <span class="token punctuation">-</span> docker build <span class="token punctuation">-</span><span class="token punctuation">-</span>pull <span class="token punctuation">-</span>t "$CI_REGISTRY_IMAGE" .
</span><span class="code-line line-number" line="11">    <span class="token punctuation">-</span> docker push "$CI_REGISTRY_IMAGE"
</span><span class="code-line line-number" line="12">    <span class="token comment"># 运行服务</span>
</span><span class="code-line line-number" line="13">    <span class="token punctuation">-</span> if <span class="token punctuation">[</span> $(docker ps <span class="token punctuation">-</span>aq <span class="token punctuation">-</span><span class="token punctuation">-</span>filter name=docker<span class="token punctuation">-</span>service<span class="token punctuation">-</span>name) <span class="token punctuation">]</span>; then docker rm <span class="token punctuation">-</span>rf docker<span class="token punctuation">-</span>service<span class="token punctuation">-</span>name;fi
</span><span class="code-line line-number" line="14">    <span class="token punctuation">-</span> docker run <span class="token punctuation">-</span>itd <span class="token punctuation">-</span>p 5000<span class="token punctuation">:</span>5000 <span class="token punctuation">-</span><span class="token punctuation">-</span>name docker<span class="token punctuation">-</span>service<span class="token punctuation">-</span>name "$CI_REGISTRY_IMAGE"<span class="token punctuation">:</span>latest
</span><span class="code-line line-number" line="15">  <span class="token key atrule">only</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="16">    <span class="token punctuation">-</span> master
</span></code><input type="hidden" value="docker-build-master:
  # Official docker image.
  image: docker:latest
  stage: build
  services:
    - docker:dind
  before_script:
    - docker login -u &#x22;$CI_REGISTRY_USER&#x22; -p &#x22;$CI_REGISTRY_PASSWORD&#x22; $CI_REGISTRY
  script:
    - docker build --pull -t &#x22;$CI_REGISTRY_IMAGE&#x22; .
    - docker push &#x22;$CI_REGISTRY_IMAGE&#x22;
    # 运行服务
    - if [ $(docker ps -aq --filter name=docker-service-name) ]; then docker rm -rf docker-service-name;fi
    - docker run -itd -p 5000:5000 --name docker-service-name &#x22;$CI_REGISTRY_IMAGE&#x22;:latest
  only:
    - master
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <ul>
          <li><code>CI_REGISTRY_USER</code> Github 用户名 Example: <code>wangchujiang</code></li>
          <li><code>CI_REGISTRY_PASSWORD</code> 密码(personal_access_tokens)，密码是需要通过 <a href="http://g.showgold.cn/-/profile/personal_access_tokens">Gitlab > User Settings > Access Tokens > Add a personal access token</a>) 生成一个 <code>personal_access_tokens</code> 而不是真正的密码</li>
          <li><code>CI_REGISTRY</code> Registry 地址 Example: <code>192.168.188.222:8070</code></li>
          <li><code>CI_REGISTRY_IMAGE</code> Example: <code>192.168.188.222:5008/docker/docker-static-service-template</code></li>
        </ul>
        <pre class="language-yml"><code class="language-yml code-highlight"><span class="code-line line-number" line="1"><span class="token key atrule">docker-build</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="2">  <span class="token comment"># Official docker image.</span>
</span><span class="code-line line-number" line="3">  <span class="token key atrule">image</span><span class="token punctuation">:</span> docker<span class="token punctuation">:</span>latest
</span><span class="code-line line-number" line="4">  <span class="token key atrule">stage</span><span class="token punctuation">:</span> build
</span><span class="code-line line-number" line="5">  <span class="token key atrule">services</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="6">    <span class="token punctuation">-</span> docker<span class="token punctuation">:</span>dind
</span><span class="code-line line-number" line="7">  <span class="token key atrule">before_script</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="8">    <span class="token punctuation">-</span> docker login <span class="token punctuation">-</span>u "$CI_REGISTRY_USER" <span class="token punctuation">-</span>p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
</span><span class="code-line line-number" line="9">  <span class="token key atrule">script</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="10">    <span class="token punctuation">-</span> docker build <span class="token punctuation">-</span><span class="token punctuation">-</span>pull <span class="token punctuation">-</span>t "$CI_REGISTRY_IMAGE<span class="token punctuation">:</span>$CI_COMMIT_REF_SLUG" .
</span><span class="code-line line-number" line="11">    <span class="token punctuation">-</span> docker push "$CI_REGISTRY_IMAGE<span class="token punctuation">:</span>$CI_COMMIT_REF_SLUG"
</span><span class="code-line line-number" line="12">  <span class="token key atrule">except</span><span class="token punctuation">:</span>
</span><span class="code-line line-number" line="13">    <span class="token punctuation">-</span> master
</span></code><input type="hidden" value="docker-build:
  # Official docker image.
  image: docker:latest
  stage: build
  services:
    - docker:dind
  before_script:
    - docker login -u &#x22;$CI_REGISTRY_USER&#x22; -p &#x22;$CI_REGISTRY_PASSWORD&#x22; $CI_REGISTRY
  script:
    - docker build --pull -t &#x22;$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG&#x22; .
    - docker push &#x22;$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG&#x22;
  except:
    - master
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <h2 id="错误处理"><a aria-hidden="true" tabindex="-1" href="#错误处理" class="anchor"><span class="icon icon-link"></span></a>错误处理</h2>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1">gitlab ci ERROR: Uploading artifacts to coordinator<span class="token punctuation">..</span>. too large archive
</span></code><input type="hidden" value="gitlab ci ERROR: Uploading artifacts to coordinator... too large archive
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>使用管理员帐户登陆 <code>Gitlab</code> -> <code>Admin Area</code> -> <code>Settings</code> 修改 <code>Maximum artifacts size (MB)</code> 值，然后保存，然而并没有解决，我的问题是 nginx 代理造成的，最终通过修改 nginx 代理配置解决问题：</p>
        <pre class="language-nginx"><code class="language-nginx code-highlight"><span class="code-line line-number" line="1"><span class="token directive"><span class="token keyword">client_max_body_size</span>       <span class="token number">10m</span></span><span class="token punctuation">;</span>
</span></code><input type="hidden" value="client_max_body_size       10m;
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <h2 id="升级"><a aria-hidden="true" tabindex="-1" href="#升级" class="anchor"><span class="icon icon-link"></span></a>升级</h2>
        <table>
          <thead>
            <tr>
              <th>目标版本</th>
              <th>你的版本</th>
              <th>支持升级</th>
              <th>路径</th>
              <th>注意</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td><code>14.1.6</code></td>
              <td><code>13.9.2</code></td>
              <td><code>13.9.2</code> -> <code>13.12.12</code> -> <code>14.0.11</code> -> <code>14.1.6</code></td>
              <td>需要两个中间版本：<code>13.12</code> 和 <code>14.0</code>，然后是 <code>14.1</code>。</td>
              <td></td>
            </tr>
            <tr>
              <td><code>13.12.10</code></td>
              <td><code>12.9.2</code></td>
              <td><code>12.9.2</code> -> <code>12.10.14</code> -> <code>13.0.14</code> -> <code>13.1.11</code> -> <code>13.8.8</code> -> <code>13.12.10</code></td>
              <td>需要四个中间版本：<code>12.10</code>、<code>13.0</code>、<code>13.1</code> 和 <code>13.8.8</code>，然后是 <code>13.12.10</code>。</td>
              <td></td>
            </tr>
            <tr>
              <td><code>13.2.10</code></td>
              <td><code>11.5.0</code></td>
              <td><code>11.5.0</code> -> <code>11.11.8</code> -> <code>12.0.12</code> -> <code>12.1.17</code> -> <code>12.10.14</code> -> <code>13.0.14</code> -> <code>13.1.11</code> -> <code>13.2.10</code></td>
              <td>需要六个中间版本：<code>11.11</code>、<code>12.0</code>、<code>12.1</code>、<code>12.10</code>、<code>13.0</code> 和 <code>13.1</code>，然后是 <code>13.2.10</code>。</td>
              <td></td>
            </tr>
          </tbody>
        </table>
        <p>假设我是 <code>13.9.2</code> 升级到 <code>14.1.6</code>，通过官方提供的<a href="https://docs.gitlab.com/ee/update/index.html#upgrade-paths">升级路径</a> => <code>13.9.2</code> -> <code>13.12.12</code> -> <code>14.0.11</code> -> <code>14.1.6</code></p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token function">docker</span> pull gitlab/gitlab-ce:13.12.12-ce.0
</span><span class="code-line line-number" line="2"><span class="token function">docker</span> pull gitlab/gitlab-ce:13.12.15-ce.0
</span><span class="code-line line-number" line="3"><span class="token function">docker</span> pull gitlab/gitlab-ce:14.0.11-ce.0
</span><span class="code-line line-number" line="4"><span class="token function">docker</span> pull gitlab/gitlab-ce:14.0.12-ce.0
</span><span class="code-line line-number" line="5"><span class="token function">docker</span> pull gitlab/gitlab-ce:14.1.6-ce.0
</span><span class="code-line line-number" line="6"><span class="token function">docker</span> pull gitlab/gitlab-ce:14.1.7-ce.0
</span><span class="code-line line-number" line="7"><span class="token function">docker</span> pull gitlab/gitlab-ce:14.1.8-ce.0
</span><span class="code-line line-number" line="8"><span class="token function">docker</span> pull gitlab/gitlab-ce:14.8.2-ce.0
</span></code><input type="hidden" value="docker pull gitlab/gitlab-ce:13.12.12-ce.0
docker pull gitlab/gitlab-ce:13.12.15-ce.0
docker pull gitlab/gitlab-ce:14.0.11-ce.0
docker pull gitlab/gitlab-ce:14.0.12-ce.0
docker pull gitlab/gitlab-ce:14.1.6-ce.0
docker pull gitlab/gitlab-ce:14.1.7-ce.0
docker pull gitlab/gitlab-ce:14.1.8-ce.0
docker pull gitlab/gitlab-ce:14.8.2-ce.0
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>我先将所有的版本下载到本地。先将 <code>13.9.2</code> 升级到 <code>14.0.11</code>，启动的时候会有提示升级需要更改配置：</p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1">There was an error running gitlab-ctl reconfigure:
</span><span class="code-line line-number" line="2">
</span><span class="code-line line-number" line="3">Removed configurations found <span class="token keyword">in</span> gitlab.rb. Aborting reconfigure.
</span><span class="code-line line-number" line="4">
</span><span class="code-line line-number" line="5">* unicorn<span class="token punctuation">[</span><span class="token string">'worker_processes'</span><span class="token punctuation">]</span> has been deprecated since <span class="token number">13.10</span> and was removed <span class="token keyword">in</span> <span class="token number">14.0</span>. Starting with GitLab <span class="token number">14.0</span>, Unicorn is no longer supported and <span class="token function">users</span> must switch to Puma, following https://docs.gitlab.com/ee/administration/operations/puma.html.
</span><span class="code-line line-number" line="6">* unicorn<span class="token punctuation">[</span><span class="token string">'worker_memory_limit_min'</span><span class="token punctuation">]</span> has been deprecated since <span class="token number">13.10</span> and was removed <span class="token keyword">in</span> <span class="token number">14.0</span>. Starting with GitLab <span class="token number">14.0</span>, Unicorn is no longer supported and <span class="token function">users</span> must switch to Puma, following https://docs.gitlab.com/ee/administration/operations/puma.html.
</span><span class="code-line line-number" line="7">* unicorn<span class="token punctuation">[</span><span class="token string">'worker_memory_limit_max'</span><span class="token punctuation">]</span> has been deprecated since <span class="token number">13.10</span> and was removed <span class="token keyword">in</span> <span class="token number">14.0</span>. Starting with GitLab <span class="token number">14.0</span>, Unicorn is no longer supported and <span class="token function">users</span> must switch to Puma, following https://docs.gitlab.com/ee/administration/operations/puma.html.
</span><span class="code-line line-number" line="8">
</span><span class="code-line line-number" line="9">Running handlers complete
</span><span class="code-line line-number" line="10">
</span><span class="code-line line-number" line="11">Chef Infra Client failed. <span class="token number">0</span> resources updated <span class="token keyword">in</span> <span class="token number">12</span> seconds
</span></code><input type="hidden" value="There was an error running gitlab-ctl reconfigure:

Removed configurations found in gitlab.rb. Aborting reconfigure.

* unicorn[&#x27;worker_processes&#x27;] has been deprecated since 13.10 and was removed in 14.0. Starting with GitLab 14.0, Unicorn is no longer supported and users must switch to Puma, following https://docs.gitlab.com/ee/administration/operations/puma.html.
* unicorn[&#x27;worker_memory_limit_min&#x27;] has been deprecated since 13.10 and was removed in 14.0. Starting with GitLab 14.0, Unicorn is no longer supported and users must switch to Puma, following https://docs.gitlab.com/ee/administration/operations/puma.html.
* unicorn[&#x27;worker_memory_limit_max&#x27;] has been deprecated since 13.10 and was removed in 14.0. Starting with GitLab 14.0, Unicorn is no longer supported and users must switch to Puma, following https://docs.gitlab.com/ee/administration/operations/puma.html.

Running handlers complete

Chef Infra Client failed. 0 resources updated in 12 seconds
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>通过回滚到 <code>13.9.2</code> 更改配置重新加载配置：</p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1">gitlab-ctl reconfigure
</span></code><input type="hidden" value="gitlab-ctl reconfigure
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>启动没有问题再升级到 <code>14.0.11</code>。</p>
        <div class="previous"><a class="prev" href="../elasticsearch.html"><svg viewBox="0 0 1024 1024" width="16" height="16" fill="currentColor">
              <path d="M842.666667 864c-8.533333 0-14.933333-2.133333-21.333334-8.533333l-341.333333-309.333334c-6.4-6.4-10.666667-14.933333-10.666667-23.466666 0-8.533333 4.266667-17.066667 10.666667-23.466667l341.333333-309.333333c12.8-12.8 34.133333-10.666667 44.8 2.133333 12.8 12.8 10.666667 34.133333-2.133333 44.8L548.266667 522.666667l315.733333 285.866666c12.8 10.666667 14.933333 32 2.133333 44.8-6.4 6.4-14.933333 10.666667-23.466666 10.666667z"></path>
              <path d="M512 864c-8.533333 0-14.933333-2.133333-21.333333-8.533333L149.333333 546.133333c-6.4-6.4-10.666667-14.933333-10.666666-23.466666 0-8.533333 4.266667-17.066667 10.666666-23.466667L490.666667 189.866667c12.8-12.8 34.133333-10.666667 44.8 2.133333 12.8 12.8 10.666667 34.133333-2.133334 44.8L217.6 522.666667 533.333333 808.533333c12.8 12.8 14.933333 32 2.133334 44.8-6.4 6.4-14.933333 10.666667-23.466667 10.666667z"></path>
            </svg>
<span>ElasticSearch 搜索服务器
</span></a><a class="next" href="../harbor.html"><span>Harbor
</span><svg viewBox="0 0 1024 1024" width="16" height="16" fill="currentColor">
              <path d="M544 522.666667c0-8.533333-4.266667-17.066667-10.666667-23.466667L192 189.866667c-12.8-12.8-34.133333-10.666667-44.8 2.133333-12.8 12.8-10.666667 34.133333 2.133333 44.8l315.733334 285.866667L149.333333 808.533333c-12.8 12.8-14.933333 32-2.133333 44.8 6.4 6.4 14.933333 10.666667 23.466667 10.666667 8.533333 0 14.933333-2.133333 21.333333-8.533333l341.333333-309.333334c6.4-6.4 10.666667-14.933333 10.666667-23.466666z"></path>
              <path d="M864 499.2l-341.333333-309.333333c-12.8-12.8-34.133333-10.666667-44.8 2.133333-12.8 12.8-10.666667 34.133333 2.133333 44.8l315.733333 285.866667-315.733333 285.866666c-12.8 12.8-14.933333 32-2.133333 44.8 6.4 6.4 14.933333 10.666667 23.466666 10.666667 8.533333 0 14.933333-2.133333 21.333334-8.533333l341.333333-309.333334c6.4-6.4 10.666667-14.933333 10.666667-23.466666 0-8.533333-4.266667-17.066667-10.666667-23.466667z"></path>
            </svg></a></div>
        <section class="article-footer"><a href="https://github.com/jaywcjlove/docker-tutorial/tree/master/docs/gitlab/README.md" class="edit-button" target="_blank" rel="noopener noreferrer"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
              <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path>
            </svg>
<span>Edit this page on GitHub</span>
</a><span class="atime">2022/04/20</span></section>
      </markdown-style>
      <nav class="tocs">
        <aside class="inner toc">
          <ol class="tocs-list">
            <li><a href="#下载镜像" class="tocs-link">下载镜像</a></li>
            <li><a href="#运行容器" class="tocs-link">运行容器</a></li>
            <li><a href="#容器手动备份" class="tocs-link">容器手动备份</a>
              <ol class="tocs-list is-collapsed">
                <li><a href="#自动备份" class="tocs-link">自动备份</a></li>
                <li><a href="#备份保留七天" class="tocs-link">备份保留七天</a></li>
              </ol>
            </li>
            <li><a href="#容器管理" class="tocs-link">容器管理</a></li>
            <li><a href="#通过-docker-compose-安装" class="tocs-link">通过 Docker Compose 安装</a></li>
            <li><a href="#使用-docker-swarm" class="tocs-link">使用 Docker Swarm</a></li>
            <li><a href="#注册-runner" class="tocs-link">注册 Runner</a>
              <ol class="tocs-list is-collapsed">
                <li><a href="#更新配置" class="tocs-link">更新配置</a></li>
                <li><a href="#升级版本" class="tocs-link">升级版本</a></li>
              </ol>
            </li>
            <li><a href="#ci-中使用编译提交镜像" class="tocs-link">CI 中使用编译提交镜像</a></li>
            <li><a href="#错误处理" class="tocs-link">错误处理</a></li>
            <li><a href="#升级" class="tocs-link">升级</a></li>
          </ol>
        </aside>
      </nav>
    </div>
    <script src="../js/demo-preview.js?v=1.29.0"></script>
    <div class="footer warpper">
      <a href="https://wangchujiang.com/#/app" target="_blank">App</a> •
      <a href="https://wangchujiang.com/#/projects" target="_blank">Projects</a> •
      <a href="https://wangchujiang.com/#/sponsor" target="_blank">Sponsor</a> •
      <a href="https://wangchujiang.com/#/app" target="_blank">More Apps</a><br><br>Released under the MIT License. Copyright © 2024 <a href="https://wangchujiang.com/#/about" target="_blank">Kenny Wong</a><br>Generated by <a href="https://github.com/jaywcjlove/idoc" target="_blank">idoc</a> v1.29.0
    </div>
    <script src="../js/tocbot.js?v=1.29.0"></script>
  </body>
</html>
